#include "Canon.h"
#include <windows.h>
#include <gl/gl.h>
CCanon::CCanon(void): m_angleCanon(this, 0){}

CCanon::~CCanon(void){}

void CCanon::doRender(void)
{
	glPushMatrix();
		drawFootOfCanon();
		glTranslatef(0, -1, 0);
		drawFootOfCanon();
		glTranslatef(1, 0.25, 0.5);
		glRotatef(m_angleCanon.getValue()*-1, 0, 1, 0);
		drawBodyOfCanon();
	glPopMatrix();
	
}

void CCanon::drawFootOfCanon()
{
	glBegin(GL_POLYGON);
		glNormal3f(0, 1, 0);
		glVertex3f(0, 0, 0);
		glVertex3f(0, 0, 1);
		glVertex3f(2, 0, 1);
		glVertex3f(2, 0, 0);
	glEnd();
	glBegin(GL_POLYGON);
		glNormal3f(0, -1, 0);
		glVertex3f(0, -0.5, 0);
		glVertex3f(0, -0.5, 1);
		glVertex3f(2, -0.5, 1);
		glVertex3f(2, -0.5, 0);
	glEnd();	
	glBegin(GL_POLYGON);
		glNormal3f(-1, 0, 0);
		glVertex3f(0, 0, 0);
		glVertex3f(0, -0.5, 0);
		glVertex3f(0, -0.5, 1);
		glVertex3f(0, 0, 1);
	glEnd();
	glBegin(GL_POLYGON);
		glNormal3f(0, 0, 1);
		glVertex3f(0, 0, 1);
		glVertex3f(0, -0.5, 1);
		glVertex3f(2, -0.5, 1);
		glVertex3f(2, 0, 1);
	glEnd();
	glBegin(GL_POLYGON);
		glNormal3f(1, 0, 0);
		glVertex3f(2, 0, 1);
		glVertex3f(2, -0.5, 1);
		glVertex3f(2, -0.5, 0);
		glVertex3f(2, 0, 0);
	glEnd();
	glBegin(GL_POLYGON);
		glNormal3f(0, 0, -1);
		glVertex3f(0, 0, 0);
		glVertex3f(0, -0.5, 0);
		glVertex3f(2, -0.5, 0);
		glVertex3f(2, 0, 0);
	glEnd();
		
}

void CCanon::drawBodyOfCanon()
{
	glBegin(GL_POLYGON);
		glNormal3f(-1,0,0);
		glVertex3f(0, 0.5, 0.5);
		glVertex3f(0, 0.5, -0.5);
		glVertex3f(0, -0.5, -0.5);
		glVertex3f(0, -0.5, 0.5);
	glEnd();

	glBegin(GL_POLYGON);
		glNormal3f(1,0,0);
		glVertex3f(3, 0.5, 0.5);
		glVertex3f(3, 0.5, -0.5);
		glVertex3f(3, -0.5, -0.5);
		glVertex3f(3, -0.5, 0.5);
	glEnd();

	glBegin(GL_POLYGON);
		glNormal3f(0, 1, 0);
		glVertex3f(0, 0.5, 0.5);
		glVertex3f(3, 0.5, 0.5);
		glVertex3f(3, 0.5, -0.5);
		glVertex3f(0, 0.5, -0.5);
	glEnd();

	glBegin(GL_POLYGON);
		glNormal3f(0, 0, -1);
		glVertex3f(0, 0.5, -0.5);
		glVertex3f(3, 0.5, -0.5);
		glVertex3f(3, -0.5, -0.5);
		glVertex3f(0, -0.5, -0.5);
	glEnd();

	glBegin(GL_POLYGON);
		glNormal3f(0, -1, 0);
		glVertex3f(0, -0.5, -0.5);
		glVertex3f(3, -0.5, -0.5);
		glVertex3f(3, -0.5, 0.5);
		glVertex3f(0, -0.5, 0.5);
	glEnd();

	glBegin(GL_POLYGON);
		glNormal3f(0, 0, 1);
		glVertex3f(0, -0.5, 0.5);
		glVertex3f(3, -0.5, 0.5);
		glVertex3f(3, 0.5, 0.5);
		glVertex3f(0, 0.5, 0.5);
	glEnd();
}